package com.ksy.common.login;

import com.ksy.common.activity.CommonBaseActivity;
import com.ksy.common.api.LoginInfo;
import com.ksy.common.utils.ParamsUtil;

import java.util.Map;

public abstract class LoginRunnable {
    protected CommonBaseActivity baseActivity;

    public LoginRunnable(CommonBaseActivity baseActivity) {
        this.baseActivity = baseActivity;
    }

    public void onStart() {
    }

    public abstract void onError(String msg);

    public abstract void onSuccess();

    public abstract void login(int type, String... params);

    protected final void loginDataDeal(boolean isSuccess, int loginType, ParamsUtil.ParamsTwo<String, String> paramsTwo, Map<String, String> data, String error) {
        if (isSuccess) {
            //登陆成功
            LoginInfo loginInfo = LoginInfo.getLoginInfo();
            loginInfo.loginType = loginType;
            if (loginType == -1) {
                //手机号登录
                loginInfo.phone = paramsTwo.first;
                loginInfo.password = paramsTwo.second;
            } else {
                loginInfo.type = paramsTwo.first;
                loginInfo.openId = paramsTwo.second;
            }
        } else {
            LoginRunnable.this.onError(error);
        }
    }


}
